//
//  TravelCollectionViewCell.m
//  艾听歌
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TravelCollectionViewCell.h"

@implementation TravelCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.title = [[UILabel alloc] init];
//        self.title.backgroundColor = [UIColor yellowColor];
        self.title.font = [UIFont systemFontOfSize:12];
        self.title.numberOfLines = 0;
        [self.contentView addSubview:self.title];
        self.title.userInteractionEnabled = YES;
        
        
        self.littleImg = [[UIImageView alloc] init];
//        self.littleImg.backgroundColor = [UIColor purpleColor];
        [self.contentView addSubview:self.littleImg];
       self.littleImg.userInteractionEnabled = YES;
        
        self.priceLabel = [[UILabel alloc] init];
//        self.priceLabel.backgroundColor = [UIColor blueColor];
        self.priceLabel.font = [UIFont systemFontOfSize:12];
        self.priceLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.priceLabel];
        self.priceLabel.userInteractionEnabled = YES;
        
        //给第二种cell上的控件加轻拍方法,让页面跳转
        UITapGestureRecognizer *Titletap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
        UITapGestureRecognizer *littleImgetap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
        UITapGestureRecognizer *pricetap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
        
        [self.title addGestureRecognizer:Titletap];
        [self.littleImg addGestureRecognizer:littleImgetap];
        [self.priceLabel addGestureRecognizer:pricetap];
      
        
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.littleImg.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height - 80);
    self.title.frame = CGRectMake(5, self.littleImg.frame.size.height + 5, self.contentView.frame.size.width - 10, 40);
    self.priceLabel.frame = CGRectMake(5, self.title.frame.origin.y + self.title.frame.size.height + 10, 50, 20);
    
}


//重写set方法
- (void)setCollectionCellModel:(Product *)collectionCellModel{
    
    _collectionCellModel = collectionCellModel;
    
    [self.littleImg sd_setImageWithURL:[NSURL URLWithString:_collectionCellModel.cover_img] placeholderImage:[UIImage imageNamed:@"holderr"]];
    
    
    
    self.title.text = _collectionCellModel.text;
    
    
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@", _collectionCellModel.price];
    
}

//轻拍手势的实现方法
- (void)tapAction{
    
#pragma mark--- 通知中心第二步:发送消息通知.
    [[NSNotificationCenter defaultCenter] postNotificationName:@"tocolletionDetail" object:self.collectionCellModel];
    

}





@end
